<template>
  <div class="mine">
    <!-- <h3>我的收货地址</h3> -->
    <NavBar title="我的收货地址" left-arrow @click-left="returnAdd" />
    <!-- <div class="addinfo" v-for="item in addlist" :key="item">
      {{ item }}
    </div> -->
    <!-- <div class="add" @click="addAdd">十添加收货地址</div> -->
    <AddressList
      v-model="chosenAddressId"
      :list="list"
      add-button-text="十添加收货地址"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
    />
  </div>
</template>

<script>
import { addressGetApi } from "../utils/api";
import { NavBar } from "vant";
import { AddressList } from "vant";
import { Toast } from "vant";
// import bus from '../bus'

export default {
  data() {
    return {
      chosenAddressId: "1",
      list: [],
    };
  },
  mounted() {
    let token = localStorage.getItem("token");
    console.log(token);
    //接口
    addressGetApi(token).then((res) => {
      console.log(res.result.resArr); //获取到了返回值
      // this.list = res.result.resArr;
      // let newcityList = [];
      this.list = res.result.resArr.map((item) => ({
        id: item.addressId,
        name: item.getName,
        tel: item.getPhone,
        address: item.address,
        status:item.status,
      }));
      // this.list=newcityList;
      //  console.log(newcityList);
      console.log(this.list);
    });
  },
  methods: {
    onAdd() {
      Toast("新增地址");
      this.$router.push("/addAdd");
    },
    // onEdit(item, index) {
    //   Toast("编辑地址:" + index);
    // },
    returnAdd() {
      this.$router.push("/home/me");
    },
  },
  components: {
    NavBar,
    AddressList,
  },
};
</script>

<style scoped>
.main {
  background: #ccc;
}
/* .add {
  font-size: 20px;
  font-weight: 800;
  color: orange;
  text-align: center;
} */
/* 标题 */
.mine /deep/ .van-ellipsis {
  font-size: 18px;
  font-weight: 700;
  display: fixed;
  top: 0;
  left: 0;
}
/* 返回箭头 */

.mine /deep/ .van-icon {
  color: black;
  font-size: 24px;
  font-weight: 700;
}
.mine /deep/ .van-icon-success {
  display: none;
}
.mine /deep/ .van-cell--borderless {
  position: relative;
}
.mine /deep/ .van-address-item__edit {
  position: absolute;
  top: 10px;
  right: 5px;
  color: orange;
  font-size: 16px;
}
.mine /deep/ .van-address-item__tag {
  position: absolute;
  top: 10px;
  left: -10px;
  background-color: orange;
}
.mine /deep/ .van-radio__label {
  padding-left: 30px;
}
.mine /deep/ .van-safe-area-bottom {
  padding: 0;
  position: static;
  margin-top: 20px;
}
.mine /deep/ .van-address-list__add {
  background-color: #fff;
  border: none;
  padding: 0;
  width: 100%;
  /* border-top: 1px solid #ccc; */
  color: orange;
  font-size: 18px;
  border-radius: 0;
  width: 100%;
  position: fixed;
  bottom: 0;
}
/* //中间部分 */
.mine /deep/ .van-address-list{
  display: fixed;
  overflow: scroll;
}
</style>
